package com.ruoyi.wetest.vo;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wetest.domain.WetestStressStatistics;
import com.ruoyi.wetest.stats.MessageMetric;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Allen
 * @description TODO
 * @Date 2024/4/30 16:07
 */
public class WeTestStressInfoVo {

    private String projectid;
    private String testId;
    private AtomicInteger instanceId;
    private AtomicInteger clientNum;
    private String token;
    private Date startDate;
    private Date stopDate;
    private MessageMetric messageMetric;
    private List<String> instancesIp;

    public WeTestStressInfoVo(String projectid, String testId, String token) {
        this.projectid = projectid;
        this.testId = testId;
        this.token = token;
        this.startDate = new Date();
        this.instanceId = new AtomicInteger();
        this.clientNum = new AtomicInteger();
        this.instancesIp =new ArrayList<>();
    }

    public String getProjectid() {
        return projectid;
    }

    public String getTestId() {
        return testId;
    }

    public AtomicInteger getInstanceId() {
        return instanceId;
    }

    public String getToken() {
        return token;
    }

    public Date getStartDate() {
        return startDate;
    }

    public Date getStopDate() {
        return stopDate;
    }



    public int getClientNum() {
        return clientNum.get();
    }

    public void incClientNum() {
        clientNum.incrementAndGet();
    }

    public void decClientNum() {
        if (clientNum.get()>0) clientNum.decrementAndGet();
    }

    public void resetClientNum(){
        clientNum.set(0);
    }

    public void stop() {
        this.stopDate = new Date();
    }

    public MessageMetric getMessageMetric() {
        return messageMetric;
    }

    public void setMessageMetric(MessageMetric messageMetric) {
        this.messageMetric = messageMetric;
    }

    public List<String> getInstancesIp() {
        return instancesIp;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("projectid", projectid)
                .append("testId", testId)
                .append("instanceId", instanceId.get())
                .append("token", token)
                .append("startDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, startDate))
                .append("clientNum", clientNum).toString();

    }


}
